package com.winchain.chainbill.bill.biz.discount.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.modules.message.keyword.SmsBillAprvRjctKeyword;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.base.po.CbOpt;
import com.winchain.chainbill.bill.biz.Bill;
import org.springframework.stereotype.Component;

@Component
public class BillDctAprvRjctMsgCmd implements ICommand<Bill<CbDct>>, ICallback<Bill<CbDct>, AcctTxRec> {
	public boolean execute(CommandContext<Bill<CbDct>> context) throws Exception {
		CbDct cbDct = (CbDct) ((Bill) context.getSource()).getSource();
		if ((cbDct != null) && (cbDct.getDctId() != null)) {
			CbOpt opt = (CbOpt) context.getValue("Operation");

			String template = "MT02626";
			SmsBillAprvRjctKeyword keyWord = new SmsBillAprvRjctKeyword();
			keyWord.setDctAmt(String.valueOf(cbDct.getDctAmt()));
			keyWord.setDctDate(SysDateUtil.parseDate(cbDct.getDctDate(), "yyyyMMdd", "yyyy-MM-dd"));

			keyWord.setRemark(opt.getRemark());

			String senderId = CommonDataUtil.getUserId();
			MessageSender.sendMessageByTmpl(senderId, template, keyWord, cbDct.getSellerId());
		}
		return false;
	}

	public boolean callback(CallbackContext<Bill<CbDct>, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}
}
